/**
 * zmn新增、修改banner
 * 文件命名格式：zmn.模块.表/功能.jas
 * @author zl
 * @since 2018/10/18
 */
layui.define(['form', 'layedit', 'laydate', 'formSelects', 'upload'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var layedit = layui.layedit;
    var laydate = layui.laydate;


    //关闭弹窗
    $('#closeCurrDialogBtn').click(function () {
        var index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
        return false;
    });
    //点击提交
    form.on('submit(zmn-coupquery-form-submit)', function (obj) {
        var data = obj.field;
        // var userId= data.userId;
        // var batchId=data.batchId;
        // var count=data.count;
        //
        // if(zmnUtil.isNull(userId)){
        //     return false;
        // } if(zmnUtil.isNull(batchId)){
        //     return false;
        // } if(zmnUtil.isNull(count)){
        //     return false;
        // }
        if (!isNumber(data.userId)) {
            layer.msg("用户ID只能为整数!");
            return false;
        }
        if (!isNumber(data.batchId)) {
            layer.msg("批次ID只能为整数!");
            return false;
        }

        //新增分发券
        $.ajax({
            type: "POST",
            url: "/coup/coupquery/sendcoup",
            data: JSON.stringify(data),
            dataType: "json",
            async: false,
            contentType: "application/json; charset=utf-8",
            success: function (json) {
                if (json.status == 200) {
                    zmnLayUtil.closeThisIframeMsg(parent, json.message, 'zmn-banner-table');
                    $(".layui-laypage-btn").click();
                }
                layer.msg(json.message);
            },
            error: function () {
                layer.msg(json.message);
            }
        });
        return false;
    });

    function isNumber(value) {         //验证是否为数字
        var patrn = /^(-)?\d+(\.\d+)?$/;
        if (patrn.exec(value) == null || value == "") {
            return false
        } else {
            return true
        }
    }

    exports('coupquery_add', {});
});